package com.ophiux.cs.application.user.impl.recore;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.application.core.Throws.ParamException;
import com.ophiux.cs.application.user.dto.updateUserRecoreInfoRequest;
import com.ophiux.cs.application.user.dto.updateUserRecoreInfoResponse;
import com.ophiux.cs.domain.user.model.entity.UserLoginRecore;
import com.ophiux.cs.domain.user.repositories.IUserRecoreRepository;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class updateUserRecoreService {
	@Autowired
	IUserRecoreRepository iUserRecoreRepository;
	
	public Result<updateUserRecoreInfoResponse> updateUserRecoreInfo(updateUserRecoreInfoRequest dto) {
		// TODO Auto-generated method stub
		Result<updateUserRecoreInfoResponse> result = new Result<updateUserRecoreInfoResponse>();
		updateUserRecoreInfoResponse res = new updateUserRecoreInfoResponse();
		try {
			try {
				//验证参数是否允许为空
				dto.paramVer();
			} catch (ParamException e) {
				return Result.fail(ResultEnum.requestParamFail.getCode(), e.getMessage()); 
			}
			
			UserLoginRecore recore = new UserLoginRecore();
			recore.setLOGIN_TIME(dto.getLOGIN_TIME());
			recore.setLOGIN_TOKEN(dto.getLOGIN_TOKEN());
			recore.setLOGOUT_TIME(dto.getLOGOUT_TIME());
			recore.setPLATFORM_ID(dto.getPLATFORM_ID());
			recore.setSTATE(dto.getSTATE());
			recore.setUSER_ID(dto.getUSER_ID());
			
			
			
			boolean upResult = iUserRecoreRepository.upUserRecoreByUserId(recore);
			res.setResult(upResult);
			
			result = Result.success(res);
		} catch (Exception e) {
			log.info("updateUserRecoreInfo接口异常：",e);
			e.printStackTrace();
			return Result.fail(ResultEnum.requestException);
		}
		
		
		return result;
	}
	
}
